import { GetRequest, PostRequest, PutRequest, DeleteRequest } from '@/utils/request'

/**
 * 博世TT设置
 */
export function setTTSetting(haId: string, data: {}) {
  return PutRequest(`/api/homeappliances/v1/${haId}/settings/1`, { data })
}

/**
 * 获取TT生活热水收藏程序
 */
export type TTProgramFavoriteType = {
  createTime: string
  customName: string
  dataJson: {
    key: string
    value: number
  }
  id: number
  updateTime: string
  wxUserHaidId: number
}
export function getProgramFavorite(haId: string) {
  return GetRequest<TTProgramFavoriteType[]>(`/api/wx/favoriteProgram/list/${haId}`)
}

/**
 * 添加收藏程序
 */
export function addProgramFavorite(haId: string, data: {}) {
  return PostRequest(`/api/wx/favoriteProgram/addv1/${haId}`, data, { ignoreErrorTips: true })
}

/**
 * 删除收藏程序
 */
export function deleteProgramFavorite(id: number) {
  return DeleteRequest(`/api/wx/favoriteProgram/delete/${id}`)
}

/**
 * tt房间详情数据
 */
export type TTRoomDetailType = {
  default: string
  description: string
  key: string
  max: string
  min: string
  name: string
  param: string
  step: string
  type: string
  unit: string
  value: string | number
}
export function getTTRoomDetail(haId: string, roomId: string) {
  return PostRequest<{ [x: string]: TTRoomDetailType[] }>(`/api/homeappliances/settings/room${roomId}/${haId}`)
}
/**
 * 博世TT保存天气位置
 */
export function saveTTAddress(haId: string, lng: number, lat: number) {
  return GetRequest(`/api/wx/province/${haId}/saveAddress?lng=${lng}&lat=${lat}`)
}

/**
 * TT获取房间编程当前的接口
 */
export type BLTTSettingValueType = {
  default: string
  description: string
  enumValues: []
  key: string
  name: string
  param: string
  type: string
  value: string
}

export type BLTTSettingType = {
  day: string
  value: BLTTSettingValueType[]
}

export function getBLTTSetting(haId: string, data: {}) {
  return PostRequest<BLTTSettingType>(`/api/homeappliances/${haId}/blsettings`, data)
}

export function getBLTTSpecialSetting(haId: string, data: {}) {
  return PostRequest<{ blSettings: BLTTSettingValueType[] }>(`/api/homeappliances/getBlSettings/${haId}`, data)
}

/**
 * 博世TT获取上报燃气量
 */
export type QueryNewGasReportType = {
  hasNext: boolean
  hasPrevious: boolean
  gasList: { date: string; gas: boolean }[]
}
export function queryNewGasReport(haId: string, type: string, data: {}) {
  return PostRequest<QueryNewGasReportType>(`/api/homeappliances/v2/${haId}/${type}/gas`, data)
}

/**
 * 博世TT是否有历史燃气量
 * @param haId
 * @returns
 */
export function checkGas(haId: string) {
  return PostRequest(`/api/homeappliances/${haId}/checkGas`)
}

/**
 * 获取ota固件升级列表-MR120
 */
export type OtaUpgradeListType = {
  changeLog: string
  pid: string
  serverversion: string
  upgrade: boolean
  upgradingVersion: string
  url: string
  version: string
}
export function getOtaUpgradeList(haId: string) {
  return GetRequest<OtaUpgradeListType[]>(`/api/OEMhomeappliances/v2/firmwareVersion/${haId}`, void 0, {
    ignoreErrorTips: true,
  })
}

/**
 * ota固件升级下发指令-MR120
 */
export function getOtaUpgradeCommandIssuing(haId: string, data: {}) {
  return PostRequest<OtaUpgradeListType[]>(`/api/OEMhomeappliances/v2/firmware/${haId}`, data)
}

/**
 * TT-修改房间名称
 */
export function renameRoomName(data: {}) {
  return PostRequest(`/api/homeappliances/modifyBranch/roomName`, data, {
    ignoreErrorTips: true,
  })
}
